package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.module.entity.LabelInfo;
import com.atguigu.lease.module.enums.ItemType;
import com.atguigu.lease.web.admin.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/label")
@Tag(name = "标签信息管理",description = "labelInfoController")
public class LabelInfoController {

    @Autowired
    private LabelInfoService labelInfoService;

    @GetMapping("getList")
    @Operation(summary = "getList")
    public Result<List<LabelInfo>> getList(@RequestParam ItemType type){
        LambdaQueryWrapper<LabelInfo>lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LabelInfo::getType,type);
        return Result.ok(labelInfoService.list(lambdaQueryWrapper));
    }

    @PostMapping("saveOrUpdate")
    @Operation(summary = "保存或更新")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo){
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.ok();
    }

    @DeleteMapping("delete")
    @Operation(summary = "删除标签信息")
    public Result delete(@RequestParam Long id){
        labelInfoService.removeById(id);
        return Result.ok();
    }


}
